package com.deltabravomedia.theoldtoad.server;

import java.io.IOException;
import java.util.Date;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class CreateCrewServlet extends HttpServlet {

	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		
		String name = req.getParameter("name");
		String age = req.getParameter("age");
		String hometown = req.getParameter("hometown");
		String education = req.getParameter("education");
		String family = req.getParameter("family");
		String favDrink = req.getParameter("favDrink");
		String favFood = req.getParameter("favFood");
		String favTeam = req.getParameter("favTeam");
		String passions = req.getParameter("passions");
		String likes = req.getParameter("likes");
		String dislikes = req.getParameter("dislikes");
		String redirect = "/addCrew.jsp";

		Crew starter = new Crew(name, age, hometown, education, family,
				favDrink, favFood, favTeam, passions, likes, dislikes, new Date());
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(starter);
		} finally {
			pm.close();
		}
	
		resp.sendRedirect(redirect);
	}
}
